package com.portal.system.controller;

import com.portal.common.core.web.controller.BaseController;
import com.portal.common.core.web.domain.AjaxResult;
import com.portal.common.core.web.page.TableDataInfo;
import com.portal.common.log.annotation.Log;
import com.portal.common.log.enums.BusinessType;
import com.portal.common.security.annotation.RequiresPermissions;
import com.portal.system.domain.SysAccessApp;
import com.portal.system.service.SysAccessAppService;
import com.portal.common.core.utils.poi.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Slf4j
@RestController()
@RequestMapping("/sysAccessApp")
public class SysAccessAppController extends BaseController {
    @Resource
    private SysAccessAppService sysAccessAppService;
    /**
     * 查询接入应用列表
     */
    //@RequiresPermissions("system:accessApp:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAccessApp sysAccessApp)
    {
        startPage();
        List<SysAccessApp> list = sysAccessAppService.selectSysAccessAppList(sysAccessApp);
        return getDataTable(list);
    }

    /**
     * 导出接入应用列表
     */
    //@RequiresPermissions("system:accessApp:export")
    @Log(title = "接入应用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAccessApp sysAccessApp)
    {
        List<SysAccessApp> list = sysAccessAppService.selectSysAccessAppList(sysAccessApp);
        ExcelUtil<SysAccessApp> util = new ExcelUtil<SysAccessApp>(SysAccessApp.class);
        util.exportExcel(response, list, "接入应用数据");
    }

    /**
     * 获取接入应用详细信息
     */
    //@RequiresPermissions("system:accessApp:query")
    @GetMapping(value = "/{appId}")
    public AjaxResult getInfo(@PathVariable("appId") Long appId)
    {
        return AjaxResult.success(sysAccessAppService.selectSysAccessAppByAppId(appId));
    }

    /**
     * 新增接入应用
     */
    //@RequiresPermissions("system:accessApp:add")
    @Log(title = "接入应用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAccessApp sysAccessApp)
    {
        return toAjax(sysAccessAppService.insertSysAccessApp(sysAccessApp));
    }

    /**
     * 修改接入应用
     */
    //@RequiresPermissions("system:accessApp:edit")
    @Log(title = "接入应用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAccessApp sysAccessApp)
    {
        return toAjax(sysAccessAppService.updateSysAccessApp(sysAccessApp));
    }

    /**
     * 删除接入应用
     */
    //@RequiresPermissions("system:accessApp:remove")
    @Log(title = "接入应用", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAccessAppService.deleteSysAccessAppByAppIds(ids));
    }

}
